package pw.archipelag.loaderGame.panel.scores {
	import flash.text.TextField;
	import base.tf.TextFieldUtils;
	import pw.archipelag.loaderGame.interfaceGame.skinsPanel.SkinTf;
	import pw.archipelag.loaderGame.interfaceGame.skinsPanel.SkinScores;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	public class ItemScore extends ItemScoreAbstract {
		private var objScore: Object;
		
		private var tfLp: TextField;
		private var tfLogin: TextField;
		private var tfScorePoints: TextField;
		private var tfScorePercent: TextField;
		
		public function ItemScore(objScore: Object, isEvenOdd: uint): void {
			this.objScore = objScore;
			super(isEvenOdd);
			this.tfLp = this.createTf();
			this.tfLogin = this.createTf();
			this.tfScorePercent = this.createTf();
			this.tfScorePoints = this.createTf();
		}
		
		private function createTf(): TextField {
			var tf: TextField = TextFieldUtils.createTextField((new SkinTf()).tFormat);
			this.addChild(tf);
			return tf;
		}
		
		override public function draw(skinScores: SkinScores): void {
			skinScores.skinTf.drawToTf(this.tfLp);
			this.setMaxWidthForTf(this.tfLp, "8888", this.objScore.lp);
			skinScores.skinTf.drawToTf(this.tfLogin);
			this.setMaxWidthForTf(this.tfLogin, "GRZEGORZ BRZĘCZYSZCZYKIEWICZ", String(this.objScore.login).toUpperCase());
			skinScores.skinTf.drawToTf(this.tfScorePoints);
			this.setMaxWidthForTf(this.tfScorePoints, "888888", this.objScore.scorePoints); //MathExt.addZerosBeforeNumberAndReturnString(Math.floor(objScore.score / 60), 2) + ":" + MathExt.addZerosBeforeNumberAndReturnString(objScore.score % 60, 2)
			skinScores.skinTf.drawToTf(this.tfScorePercent);
			this.setMaxWidthForTf(this.tfScorePercent, "100 %", this.objScore.scorePercent + " %");
			ItemScoreAbstract.WIDTH = this.tfLp.width + this.tfLogin.width + this.tfScorePoints.width + this.tfScorePercent.width;
			ItemScoreAbstract.HEIGHT = this.tfLp.height;
			super.draw(skinScores);
		}
		
		private function setMaxWidthForTf(tf: TextField, textWithMaxWidth: String, text: String): void {
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.text = textWithMaxWidth;
			var maxWidth: Number = tf.width;
			tf.autoSize = TextFieldAutoSize.NONE;
			tf.width = maxWidth;
			tf.text = text;
		}
		
		internal function changeColorTfsCurrentLoginToHighlighted(colorTFHighlight: uint): void {
			this.changeColorTfCurrentLoginToHighlighted(this.tfLp, colorTFHighlight);
			this.changeColorTfCurrentLoginToHighlighted(this.tfLogin, colorTFHighlight);
			this.changeColorTfCurrentLoginToHighlighted(this.tfScorePoints, colorTFHighlight);
			this.changeColorTfCurrentLoginToHighlighted(this.tfScorePercent, colorTFHighlight);
		}
		
		private function changeColorTfCurrentLoginToHighlighted(tfCurrentLogin: TextField, colorTFHighlight: uint): void {
			var tFormatCurrentLogin: TextFormat;
			tFormatCurrentLogin = tfCurrentLogin.getTextFormat();
			tFormatCurrentLogin.color = colorTFHighlight;
			tfCurrentLogin.setTextFormat(tFormatCurrentLogin);
		}
		
		override public function set width(value: Number): void {
			var marginBetweenTfs: Number = (value - ItemScoreAbstract.WIDTH) / 3;
			this.tfLogin.x = this.tfLp.x + this.tfLp.width + marginBetweenTfs;
			this.tfScorePoints.x = this.tfLogin.x + this.tfLogin.width + marginBetweenTfs;
			this.tfScorePercent.x = this.tfScorePoints.x + this.tfScorePoints.width + marginBetweenTfs;
			super.width = value;
		}
		
	}

}